from google.appengine.ext import webapp
from DataClass.WebsiteRec import WebsiteRec
from google.appengine.api import users
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from AdminBase import AdminBase

import os
import cgi

class DeleteWebsiteHandler(AdminBase):
    def GetTemplateFileName(self):
        return 'Pages/deletewebsite.html'
        
    def GetBreadcrumbList(self):
        return [['main', 'admin'],['websites', 'editwebsites'],['delete website']]
    
    def GetTemplateValuesDict(self, template_values, user):
        retval = template_values

        querystring=cgi.FieldStorage()
        sitename=querystring.getvalue('sitename')
        Website=None
    
        # if sitename:
        if not sitename:
            sitename = ''
            
        Website = WebsiteRec.GetWebsiteBySiteName(sitename)

        if Website:
            retval['website'] = Website
    
        return retval

    def DoPost(self, user):
        Website = WebsiteRec.GetWebsiteBySiteName(self.request.get('sitename'))

        if Website:
            db.delete(Website)

        self.redirect('/editwebsites')
